package dynamic.injector;

import dynamic.metadata.DTableInfo;
import dynamic.mybatisplus.core.injector.DAbstractMethod;
import dynamic.mybatisplus.core.injector.methods.*;


import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class DDefaultSqlInjector extends DAbstractSqlInjector {

    @Override
    public List<DAbstractMethod> getMethodList(Class<?> mapperClass, DTableInfo tableInfo) {
        Stream.Builder<DAbstractMethod> builder = Stream.<DAbstractMethod>builder()
                .add(new Insert())
                .add(new Delete())
                .add(new Update())
                .add(new SelectCount())
                .add(new SelectMaps())
                .add(new SelectObjs())
                .add(new SelectList());
        if (tableInfo.havePK()) {
            builder.add(new DeleteById())
                    .add(new DeleteBatchByIds())
                    .add(new UpdateById())
                    .add(new SelectById())
                    .add(new SelectBatchByIds());
        } else {
            logger.warn(String.format("%s ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.",
                    tableInfo.getEntityType()));
        }
        return builder.build().collect(toList());
    }
}